package global

import (
	"MoSkeleton/framework"
	"MoSkeleton/framework/mo_gin"
	"MoSkeleton/framework/mo_gorm"
	"MoSkeleton/framework/utils"
	"go.uber.org/zap"
)

var (
	MoLogger, _ = zap.NewDevelopment()
)

var (
	configEvent *ConfigEvent
)

func DoInitSystem() {
	if err := configEvent.OnInitSystem(); err != nil {
		MoLogger.Warn("onInit system failed: ", zap.Error(err))
	}
}

func AfterInitSystem() {
	if err := configEvent.OnAfterInitSystem(); err != nil {
		MoLogger.Warn("after system failed: ", zap.Error(err))
	}
}

func init() {
	configEvent = new(ConfigEvent)
	MoLogger = framework.MoLogger
	mo_gorm.PersistentDb = &framework.ConfigContainerInst.AppStorageProperty.App.PersistentDb
	mo_gin.CommonGin = &framework.ConfigContainerInst.AppProperty.App.Gin
	utils.CommonGin = &framework.ConfigContainerInst.AppProperty.App.Gin
	utils.SecurityPropertyInst = &framework.ConfigContainerInst.AppProperty.App.Security
	if mo_gin.CommonGin.Mode == "" {
		mo_gin.CommonGin.Mode = framework.ConfigContainerInst.BootstrapProperty.Sys.Profile.Mode
	}
}
